<?php

namespace App\Store\Controllers\Basic;

use App\Common\Services\Store\Common as StoreCommon;
use App\Http\Controllers\Controller;
use App\Store\Models\Basic\GoodsBrand;
use App\Store\Models\Basic\GoodsContent;
use App\Store\Models\Basic\GoodsCraft;
use App\Store\Models\Basic\GoodsPricetype;
use App\Store\Models\Basic\TemplateQuality;
use App\Store\Models\Basic\TemplateTag;
use App\Store\Models\Goods\GoodsReplenishInfolist;
use App\Store\Models\Goods\GoodsStockin;
use App\Store\Models\Goods\GoodsStockinInfolist;
use App\Store\Models\Goods\GoodsStockinPrint;
use App\Store\Models\Goods\GoodsStockList;
use Illuminate\Http\Request;
use App\Store\Validate\Basic\TemplateTag as ValidateBasicTemplateTag;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Facades\Excel;
use App\Common\Services\CommonExcelExport;
use App\Store\Models\Account\SiteStore;

/**
 * 模板、标签
 */
class TemplateTagController extends Controller
{

    public function dopostadd(Request $request)
    {
        $req_data = $request->only(['store_ids', 'tag_name', 'remark']);
        $Validate = new ValidateBasicTemplateTag();
        if (!$Validate->check($req_data)) {
            return response()->json(['code' => '001', 'msg' => $Validate->getError()]);
        }

        $accountinfo = StoreCommon::getCurrentAccountinfo($request);
        $cp_id = $accountinfo['cp_id'];

        $store_ids = $req_data['store_ids'];
        $store_ids = is_array($store_ids) ? $store_ids : (is_array(json_decode($store_ids, true)) ? json_decode($store_ids, true) : []);

        DB::beginTransaction();
        try {
            foreach ($store_ids as $store_id) {
                $tag_data = $req_data + [
                        'store_id' => $store_id,
                        'cp_id' => $cp_id,
                        'create_at' => time(),
                        'create_account_id' => $accountinfo['id'],
                        'create_account_real_name' => $accountinfo['real_name'],
                        'report_json' => config('tag.label_tag')
                    ];
                TemplateTag::create($tag_data);
            }
            DB::commit();
        } catch (\Exception $e) {
            DB::rollBack();
            return response()->json(['code' => '001', 'msg' => '操作失败' . $e->getMessage()]);
        }

        return response()->json(['code' => '000', 'msg' => '操作成功']);
    }

    public function dopostedit(Request $request)
    {
        $req_data = $request->only(['id', 'store_id', 'tag_name', 'remark']);
        $Validate = new ValidateBasicTemplateTag('edit');
        if (!$Validate->check($req_data)) {
            return response()->json(['code' => '001', 'msg' => $Validate->getError()]);
        }


        $accountinfo = StoreCommon::getCurrentAccountinfo($request);

        $tag_data = $req_data + [
                'update_at' => time(),
                'update_account_id' => $accountinfo['id'],
                'update_account_real_name' => $accountinfo['real_name'],
            ];
        TemplateTag::where('id', $req_data['id'])->update($tag_data);
        return response()->json(['code' => '000', 'msg' => '操作成功']);
    }

    public function dodel(Request $request)
    {
        $req_data = $request->only(['id']);
        $Validate = new ValidateBasicTemplateTag('del');
        if (!$Validate->check($req_data)) {
            return response()->json(['code' => '001', 'msg' => $Validate->getError()]);
        }

        TemplateTag::where('id', $req_data['id'])->update([
            'is_del' => 2,
            'update_at' => time(),
        ]);
        return response()->json(['code' => '000', 'msg' => '删除成功']);
    }

//    public function getListDefaultId(array $data)
//    {
//        $id = 0;
//        if(empty($data['list'])){
//            return $id;
//        }
//        foreach($data['list'] as $item){
//            if($item['is_default_value'] == 2){
//                $id = $item['id'];
//                break;
//            }
//        }
//        return $id;
//    }

    public function getlist(Request $request)
    {
        $list = TemplateTag::getList($request);
//        if(!empty($list)){
//            $default_value = $this->getListDefaultId($list);
//            $list['default_value'] = $default_value;
//        }
        return response()->json(['code' => '000', 'msg' => '获取成功', 'data' => $list]);
    }

    public function doexport(Request $request)
    {
        $list = TemplateTag::getList($request)['list'];
        $exceldata = [];
        $storeNames = array_unique(array_map(function ($item) {
            return $item['storeinfo']['store_name'];
        }, $list));
        $row = [
            ['tag_name' => '标签模板'],
            ['tag_name' => '所属门店：' . join(',', $storeNames)],
            [
                'tag_name' => '模板名称',
                'store_name' => '门店名称',
                'is_default_value' => '是否默认',
                'remark' => '备注',
                'report_json_file_path' => '模板文件路径',
            ]
        ];

        foreach ($list as $val) {
            if (!$val['report_json_file_path']) {
                $path = 'template/tag/' . md5(time() . mt_rand(1000, 9999));
                Storage::put($path, $val['report_json']);
                $val['report_json_file_path'] = $path;
                TemplateTag::where(['id' => $val['id']])->update(['report_json_file_path' => $path]);
            }
            $exceldata[] = [
                'tag_name' => $val['tag_name'],
                'store_name' => $val['storeinfo']['store_name'],
                'is_default_value' => ($val['is_default_value'] == '2') ? '是' : '',
                'remark' => $val['remark'],
                'report_json_file_path' => $val['report_json_file_path']
            ];
        }

        $filename = '标签模板导出_' . time() . '.xlsx';
        return Excel::download(new CommonExcelExport($row, $exceldata), $filename);
    }

    public function doimport(Request $request)
    {
        $store_ids = $request->store_ids ?? [];
        $store_ids = is_array($store_ids) ? $store_ids : (is_array(json_decode($store_ids, true)) ? json_decode($store_ids, true) : []);
        if (count($store_ids) <= 0) {

            return response()->json(['code' => '001', 'msg' => '无效门店参数']);
        }
        $accountinfo = StoreCommon::getCurrentAccountinfo($request);
        $cp_id = $accountinfo['cp_id'];
        $filepathname = $request->filepathname;
        if ($filepathname != '' && file_exists(storage_path() . $filepathname) && is_file(storage_path() . $filepathname)) {
            $file = storage_path() . $filepathname;
            $data = Excel::toArray(null, $file)[0];
            foreach ($store_ids as $store_id) {
                $storeinfo = SiteStore::where(['id' => $store_id, 'cp_id' => $cp_id])->first();
                if (!$storeinfo) {
                    return response()->json(['code' => '001', 'msg' => '无效门店参数']);
                }
            }
            $ins_data = [];
            foreach ($data as $key => $val) {
                if ($key == 0 && (strpos('标签模板', (string)$val[0]) !== false)) {
                    continue;
                }
                if ($key == 1 && (strpos((string)$val[0], '所属门店') !== false)) {
                    continue;
                }
                // 过滤表头
                if (strpos((string)$val[0], '模板名称') !== false || strpos((string)$val[1], '门店名称') !== false) { //表头跳过
                    continue;
                }
                if (count($val) != 5) {
                    return response()->json(['code' => '001', 'msg' => '导入数据格式错误']);
                }

                if ($val[0] == '合计' || empty($val[0])) {
                    continue;
                }

                $valdata = [
                    'cp_id' => $cp_id,
                    'tag_name' => $val[0],
                    'is_default_value' => !empty($val[2]) ? (($val[2] == '是') ? 2 : 1) : 1,
                    'remark' => !empty($val[3]) ? strval($val[3]) : '',
                    'create_at' => time(),
                    'create_account_id' => $accountinfo['id'],
                    'create_account_real_name' => $accountinfo['real_name'],
                    'report_json' => !empty($val[4]) ? (!empty(Storage::get($val[4])) ? Storage::get($val[4]) : config('tag.label_tag')) : config('tag.label_tag'),
                ];

                foreach ($store_ids as $store_id) {
                    $item = $valdata;
                    $path = 'template/tag/' . md5(time() . mt_rand(1000, 9999));
                    Storage::put($path, $valdata['report_json']);
                    $item['report_json_file_path'] = $path;
                    $item['store_id'] = $store_id;
                    $ins_data[] = $item;
                }
            }
            TemplateTag::insert($ins_data);
            return response()->json(['code' => '000', 'msg' => '数据导入成功']);
        } else {
            return response()->json(['code' => '001', 'msg' => '文件不存在'], 200);
        }
    }

    public function designtag(Request $request)
    {

        $id = $request->id ?? 0;
        $info = TemplateTag::where(['id' => $id, 'is_del' => 1])->first();
        if (!$info) {
            return response()->json(['code' => '001', 'msg' => '标签不存在']);
        }

        if ($info->report_json) {
            $report_json = $info->report_json;
            // return response()->json(['code' => '000', 'msg' => '获取成功', 'data' => ['report_json'=>json_decode($info->report_json,true)]]);
        } else {
            //$report_json='{"Name":"Report","Width":"5cm","Layers":[{"Name":"default"}],"CustomProperties":[{"Name":"DisplayType","Value":"Page"},{"Name":"SizeType","Value":"Default"},{"Name":"PaperOrientation","Value":"Portrait"}],"Page":{"PageWidth":"5cm","PageHeight":"3.5cm","RightMargin":"0in","LeftMargin":"0in","TopMargin":"0in","BottomMargin":"0in","Columns":1,"ColumnSpacing":"0in"},"DataSources":[{"Name":"DataSource","ConnectionProperties":{"DataProvider":"JSONEMBED","ConnectString":"jsondata=[{\\n        \"证书号\": \"\",\\n        \"精度\": \"\",\\n        \"颜色\": \"\",\\n        \"工费\": 0.00,\\n        \"工费单价\": 0.00,\\n        \"商品条码\": \"SLP123456\",\\n        \"商品名称\": \"纯金手镯\",\\n        \"主石重\": \"0.000\",\\n        \"副石重\": \"0.000\",\\n        \"标签价\": 100.00,\\n        \"重量\": \"20.800\",\\n        \"圈号\": \"12\",\\n        \"含量\": \"10\"\\n}]"}}],"FixedPage":{"Pages":[{"Width":"3cm","Height":"5cm"}]},"DataSets":[{"Name":"DataSet","Fields":[{"Name":"证书号","DataField":"证书号"},{"Name":"精度","DataField":"精度"},{"Name":"颜色","DataField":"颜色"},{"Name":"工费","DataField":"工费"},{"Name":"工费单价","DataField":"工费单价"},{"Name":"商品条码","DataField":"商品条码"},{"Name":"商品名称","DataField":"商品名称"},{"Name":"主石重","DataField":"主石重"},{"Name":"副石重","DataField":"副石重"},{"Name":"标签价","DataField":"标签价"},{"Name":"重量","DataField":"重量"},{"Name":"圈号","DataField":"圈号"},{"Name":"含量","DataField":"含量"}],"Query":{"DataSourceName":"DataSource","CommandText":"jpath=$.[*]"},"CaseSensitivity":"Auto","KanatypeSensitivity":"Auto","AccentSensitivity":"Auto","WidthSensitivity":"Auto"}]}';

            //$report_json='{"Name":"Report1","Width":"5cm","Layers":[{"Name":"default"}],"CustomProperties":[{"Name":"DisplayType","Value":"Page"},{"Name":"SizeType","Value":"Default"},{"Name":"PaperOrientation","Value":"Portrait"},{"Name":"CollapseWhiteSpace","Value":"True"}],"Page":{"PageWidth":"5cm","PageHeight":"3.5cm","RightMargin":"0in","LeftMargin":"0in","TopMargin":"0in","BottomMargin":"0in","Columns":1,"ColumnSpacing":"0in"},"DataSources":[{"Name":"DataSource","ConnectionProperties":{"DataProvider":"JSONEMBED","ConnectString":"jsondata=[{\\n        \"证书号\": \"\",\\n        \"精度\": \"\",\\n        \"颜色\": \"\",\\n        \"工费\": 0.00,\\n        \"工费单价\": 0.00,\\n        \"商品条码\": \"123456\",\\n        \"商品名称\": \"纯金手镯\",\\n        \"主石重\": \"0.000\",\\n        \"副石重\": \"0.000\",\\n        \"标签价\": 100.00,\\n        \"重量\": \"20.800\",\\n        \"圈号\": \"12\",\\n        \"含量\": \"10\"\\n}]"}}],"FixedPage":{"Pages":[{"ReportItems":[{"Type":"textbox","Name":"商品","CanGrow":true,"KeepTogether":true,"Value":"商品名","Style":{"PaddingLeft":"2pt","PaddingRight":"2pt","PaddingTop":"2pt","PaddingBottom":"2pt"},"Width":"0.5417in","Height":"0.25in"},{"Type":"textbox","Name":"文本框1","ZIndex":1,"CanGrow":true,"KeepTogether":true,"Value":"=Fields!商品名称.Value","Style":{"PaddingLeft":"2pt","PaddingRight":"2pt","PaddingTop":"2pt","PaddingBottom":"2pt"},"Left":"0.5625in","Width":"0.6186in","Height":"0.25in"},{"Type":"textbox","Name":"文本框2","ZIndex":2,"CanGrow":true,"KeepTogether":true,"Value":"=Fields!商品条码.Value","Style":{"PaddingLeft":"2pt","PaddingRight":"2pt","PaddingTop":"2pt","PaddingBottom":"2pt"},"Left":"0.0521in","Top":"0.3854in","Width":"1in","Height":"0.25in"},{"Type":"barcode","Name":"Barcode1","ZIndex":3,"Value":"=Fields!商品条码.Value","Symbology":"Code_128auto","Style":{"FontFamily":"Courier New","FontSize":"8pt"},"Left":"0.0105in","Top":"1.0835in","Width":"1.1146in","Height":"0.25in"}],"Width":"3cm","Height":"5cm"}],"Group":{"Name":"条码分组","GroupExpressions":["=Fields!商品条码.Value"]},"DataSetName":"DataSet"},"DataSets":[{"Name":"DataSet","Fields":[{"Name":"证书号","DataField":"证书号"},{"Name":"精度","DataField":"精度"},{"Name":"颜色","DataField":"颜色"},{"Name":"工费","DataField":"工费"},{"Name":"工费单价","DataField":"工费单价"},{"Name":"商品条码","DataField":"商品条码"},{"Name":"商品名称","DataField":"商品名称"},{"Name":"主石重","DataField":"主石重"},{"Name":"副石重","DataField":"副石重"},{"Name":"标签价","DataField":"标签价"},{"Name":"重量","DataField":"重量"},{"Name":"圈号","DataField":"圈号"},{"Name":"含量","DataField":"含量"}],"Query":{"DataSourceName":"DataSource","CommandText":"jpath=$.[*]"},"CaseSensitivity":"Auto","KanatypeSensitivity":"Auto","AccentSensitivity":"Auto","WidthSensitivity":"Auto"}]}';

            $report_json = config('tag.label_tag');
            // return response()->json(['code' => '000', 'msg' => '获取成功', 'data' => ['report_json'=>json_decode($report_json,true)]]);
        }
        return response()->json(json_decode($report_json, true));
    }

    /**
     * 标签打印
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function tagPrint(Request $request)
    {

        $id = $request->id ?? 0;
        $type = intval($request->type)??0;
        $cp_id = intval($request->cp_id)??0;
        $stockIds =$request->stockIds ?? '';
        $info = TemplateTag::query()->where(['id' => $id, 'is_del' => 1,'cp_id'=>$cp_id])->first();
        if (empty($info)) {
            return response()->json(['code' => '001', 'msg' => '标签不存在']);
        }

        $report_json = !empty($info->report_json)?$info->report_json:config('tag.label_tag');

        if(empty($type)){
            return response()->json(['code' => '001', 'msg' => '类型不存在']);
        }

        if(empty($cp_id)){
            return response()->json(['code' => '001', 'msg' => '企业不存在']);
        }

        if(empty($stockIds)){
            return response()->json(['code' => '001', 'msg' => '数据不存在']);
        }else{
            $stockIds = explode(',',$stockIds);
        }

        $list=[];
        if ($type == 1) {
            $list = GoodsStockinInfolist::with(['goods_category', 'goods_style', 'goods_craft', 'goods_pricetype', 'goods_brand', 'goods_content'])
                ->where(['cp_id' => $cp_id])
                ->whereIn('id', $stockIds)
                ->get()
                ->toArray();
        } elseif ($type == 2) {
            //库存打印
            $list = GoodsStockList::with(['goods_category', 'goods_style', 'goods_craft', 'goods_pricetype', 'goods_brand', 'goods_content'])
            ->where(['cp_id' => $cp_id,'is_del'=>1])
                ->whereIn('id', $stockIds)
                ->get()
                ->toArray();

        } elseif ($type == 3) {
            //补货打印
            $list = GoodsReplenishInfolist::with(['goods_category', 'goods_style', 'goods_craft', 'goods_pricetype', 'goods_brand'])
                ->where(['cp_id' => $cp_id,'is_del'=>1])
                ->whereIn('id', $stockIds)
                ->get()
                ->toArray();
        }elseif ($type == 4) {

            $list = GoodsStockinPrint::with(['goods_category', 'goods_style'])
                ->where(['cp_id' => $cp_id])
                ->whereIn('id', $stockIds)
                ->get()
                ->toArray();
            $craftIds = array_values(array_unique(array_filter(array_column($list,'goods_craft_id'))));
            $pricetype_ids = array_values(array_unique(array_filter(array_column($list,'goods_pricetype_id'))));
            $brand_ids = array_values(array_unique(array_filter(array_column($list,'goods_brand_id'))));
            $content_ids = array_values(array_unique(array_filter(array_column($list,'goods_content_id'))));


            $goodsCraft=[];
            if(!empty($craftIds)){
                $goodsCraft = GoodsCraft::query()
                    ->where(['cp_id'=>$cp_id,'is_del'=>1])
                    ->whereIn('id',$craftIds)
                    ->get(['id','craft_name'])
                    ->pluck('craft_name','id')
                    ->toArray();
            }
            $goodsPricetype=[];
            if(!empty($pricetype_ids)){
                $goodsPricetype = GoodsPricetype::query()
                    ->where(['cp_id'=>$cp_id,'is_del'=>1])
                    ->whereIn('id',$pricetype_ids)
                    ->get(['id','pricetype_name'])
                    ->pluck('pricetype_name','id')
                    ->toArray();
            }
            $goodsBrand=[];
            if(!empty($brand_ids)){
                $goodsBrand = GoodsBrand::query()
                    ->where(['cp_id'=>$cp_id,'is_del'=>1])
                    ->whereIn('id',$brand_ids)
                    ->get(['id','brand_name'])
                    ->pluck('brand_name','id')
                    ->toArray();
            }
            $goodsContent=[];
            if(!empty($content_ids)){
                $goodsContent = GoodsContent::query()
                    ->where(['cp_id'=>$cp_id,'is_del'=>1])
                    ->whereIn('id',$content_ids)
                    ->get(['id','content_name'])
                    ->pluck('content_name','id')
                    ->toArray();
            }

            foreach ($list as &$item){
                $item['craft_name'] =$goodsCraft[$item['goods_craft_id']]??'';
                $item['pricetype_name'] =$goodsPricetype[$item['goods_pricetype_id']]??'';
                $item['brand_name'] =$goodsBrand[$item['goods_brand_id']]??'';
                $item['content'] =$goodsContent[$item['goods_content_id']]??'';

            }
        }

        $jsonData=[];
        if(!empty($list)){
            foreach ($list as $val) {
                $jsonData[] = [
                    'goods_sn_code' => $val['goods_sn_code'],
                    'goods_name' => $val['goods_name'],
                    'style_name' => empty($val['goods_style']) ? '' : $val['goods_style']['style_name'],
                    'category_name' => empty($val['goods_category']) ? '' : $val['goods_category']['category_name'],
                    'content' => !empty($val['content']??'')?$val['content']:($val['goods_content']['content_name']??''),
                    'piece_weight' => (string)((float)$val['piece_weight']),
                    'netglod_weight' => (string)((float)$val['netglod_weight']),
                    'netglod_weight2' => (int)sprintf('%d', (float)$val['netglod_weight'] * 1000),
                    'pieceprice_fee' => $val['pieceprice_fee'] / 100,
                    'gramprice_fee' => $val['gramprice_fee'] / 100,
                    'label_price' =>  isset($val['label_price'])?($val['label_price'] / 100):0,
                    'label_price_new' => isset($val['label_price_new'])?($val['label_price_new'] / 100):0,
                    'craft_name' => !empty($val['craft_name']??'') ? $val['craft_name'] :(empty($val['goods_craft'])? '':$val['goods_craft']['craft_name']) ,
                    'c_no' => $val['c_no'],
                    's_no' => $val['s_no'],
                    'gemstone_fee1' => $val['gemstone_fee1'] / 100,
                    'gemstone_fee2' => $val['gemstone_fee2'] / 100,
                    'add_fee1' => $val['add_fee1'] / 100,
                    'add_fee2' => $val['add_fee2'] / 100,
                    'brand_name' => !empty($val['brand_name']??'')?$val['brand_name']: (empty($val['goods_brand']) ? '' : $val['goods_brand']['brand_name']),
                    'cf_no' => $val['cf_no'],
                    'cf_no_gia' => $val['cf_no_gia'],
                    'main_stone_weigth' => $val['main_stone_weigth'],
                    'main_stone_count' => $val['main_stone_count'],
                    'other_stone_weigth' => $val['other_stone_weigth'],
                    'other_stone_count' => $val['other_stone_count'],
                    'color' => $val['color'],
                    'clarity' => $val['clarity'],
                    'pricetype_name' => !empty($val['pricetype_name']??'')?$val['pricetype_name']:(empty($val['goods_pricetype']) ? '' : $val['goods_pricetype']['pricetype_name']),
                    'remark' => $val['remark'],
                    'code_url' => env('TAG_CODE_URL') . '?type=' . $type . '&id=' . $val['id'],
                ];
            }
        }

        //$jsonData = '[{"goods_sn_code":"250306145136","goods_name":"足金胸章","style_name":"胸章","category_name":"足金999.99克","content":"999.9‰","piece_weight":"0.000","netglod_weight":"20.000","netglod_weight2":20000,"pieceprice_fee":0,"gramprice_fee":0,"label_price":0,"craft_name":"","c_no":"","s_no":"","gemstone_fee1":0,"gemstone_fee2":0,"add_fee1":0,"add_fee2":0,"brand_name":"","cf_no":"","cf_no_gia":"","main_stone_weigth":"0.000","main_stone_count":0,"other_stone_weigth":"0.000","other_stone_count":0,"color":"","clarity":"","pricetype_name":"","remark":"","code_url":"https:\/\/zxbweb.wemaster.net\/codeIndex.html?type=1&id=1605"},{"goods_sn_code":"250306145136","goods_name":"足金胸章","style_name":"胸章","category_name":"足金999.99克","content":"999.9‰","piece_weight":"0.000","netglod_weight":"20.000","netglod_weight2":20000,"pieceprice_fee":0,"gramprice_fee":0,"label_price":0,"craft_name":"","c_no":"","s_no":"","gemstone_fee1":0,"gemstone_fee2":0,"add_fee1":0,"add_fee2":0,"brand_name":"","cf_no":"","cf_no_gia":"","main_stone_weigth":"0.000","main_stone_count":0,"other_stone_weigth":"0.000","other_stone_count":0,"color":"","clarity":"","pricetype_name":"","remark":"","code_url":"https:\/\/zxbweb.wemaster.net\/codeIndex.html?type=1&id=1605"}]';
        $data['code'] = 0;
        $data['data']['root'] = $jsonData;
        $data['message'] = 'ok';
        $data['templet'] = json_decode($report_json, true);
        $data['version'] = '1.0.1';

        return response()->json($data);
    }


    public function savedesigntag(Request $request)
    {
        $id = $request->id ?? 0;
        $info = TemplateTag::where(['id' => $id, 'is_del' => 1])->first();
        if (!$info) {
            return response()->json(['code' => '001', 'msg' => '标签不存在']);
        }
        $report_json = $request->report_json ?? '';
        if (!$info->report_json_file_path) {
            $path = 'template/tag/' . md5(time() . mt_rand(1000, 9999));
            Storage::put($path, $report_json);
            $info->report_json_file_path = $path;
        } else {
            $path = $info->report_json_file_path;
            Storage::put($path, $report_json);
        }

        TemplateTag::where(['id' => $id, 'is_del' => 1])->update(['report_json' => $report_json, 'report_json_file_path' => $info->report_json_file_path]);
        return response()->json(['code' => '000', 'msg' => '保存成功']);
    }


    public function copytag(Request $request)
    {
        $id = $request->id ?? 0;
        $accountinfo = StoreCommon::getCurrentAccountinfo($request);
        $cp_id = $accountinfo['cp_id'];
        $info = TemplateTag::where(['id' => $id, 'is_del' => 1, 'cp_id' => $cp_id])->first();
        if (!$info) {
            return response()->json(['code' => '001', 'msg' => '标签不存在']);
        }
        // /'store_ids', 'tag_name', 'remark'
        $tag_data = [
            'store_id' => $info->store_id,
            'cp_id' => $cp_id,
            'tag_name' => $info->tag_name,
            'remark' => $info->remark,
            'create_at' => time(),
            'update_at' => time(),
            'create_account_id' => $accountinfo['id'],
            'create_account_real_name' => $accountinfo['real_name'],
            'update_account_id' => $accountinfo['id'],
            'update_account_real_name' => $accountinfo['real_name'],
            'report_json' => $info->report_json
        ];
        TemplateTag::create($tag_data);

        return response()->json(['code' => '000', 'msg' => '复制成功']);


    }

    public function dodefaultvalue(Request $request)
    {
        $id = $request->only(['id']);
        if (!$id) {
            return response()->json(['code' => '001', 'msg' => 'id不能为空']);
        }
//        $TemplateTagObj = new TemplateTag();
//        $res = $TemplateTagObj->editDefaultvalue($request);
//        if($res){
//            return response()->json(['code' => '000', 'msg' => '设置成功']);
//        }else{
//            return response()->json(['code' => '001', 'msg' => '修改失败']);
//        }
    }


    public function getprintList()
    {

        $response = Http::get('http://127.0.0.1:18080/printerlist');

        $res = $response->body();
        return response()->json(['code' => '00', 'data' => json_decode($res, true)]);
    }





}
